﻿Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Data
Public Class Adddepartment
    'ประกาศตัวแปรตัวเชื่อมต่อ
    Dim sql As MySqlConnection

    Dim ipconnect As String

    Dim usernamedb As String
    Dim dbname As String
    Dim mysqlpass As String
    Dim id_user As String
    Dim position_user As String
    Public Sub New(ByRef mysql_pass As String, ByRef ip_connect As String, ByRef user_namedb As String, ByRef db_name As String)

        InitializeComponent()
        mysqlpass = mysql_pass
  

        ipconnect = ip_connect
        usernamedb = user_namedb
        dbname = db_name
    End Sub

    Private Sub Adddepartment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sql = New MySqlConnection
        sql.ConnectionString = "server=" + ipconnect + ";user id=" + usernamedb + ";password=" + mysqlpass + ";database=" + dbname + ";Character Set =utf8;"
        Try
            sql.Open()
            ' MsgBox("CONNECTED TO DATABASE")
        Catch ex As Exception
            MsgBox("Can't Connect to database" + ex.Message)

            Me.Close()
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader

        If Sql.State = ConnectionState.Closed Then
            Sql.Open()
        End If
        Try
            ''เช็คข้อมูลที่บังคับป้อน
            If tabdepartname.Text <> "" Then
                mySqlCommand.CommandText = "INSERT INTO Department (departmentname) VALUES ('" & tabdepartname.Text & "' );"
                mySqlCommand.CommandType = CommandType.Text
                mySqlCommand.Connection = sql
                mySqlCommand.ExecuteNonQuery()
                MsgBox("เก็บเข้าฐานข้อมูลแล้วจ้า!! by โตน ลูกพี่อารี")
                tabdepartname.Text = ""

            Else
                MsgBox("กรุณากรอกข้อมูลให้ครบถ้วนนะจ้า!! by โตน ลูกพี่อารี")
            End If


        Catch ex As Exception
            MsgBox(ex.ToString)
            sql.Close()
        End Try
    End Sub

    Private Sub เพมขอมลอปกรณToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles เพมขอมลอปกรณToolStripMenuItem.Click
        Dim NextForm As add = New add(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        Me.Hide()
        NextForm.ShowDialog()
    End Sub

    Private Sub แกไขขอมลอปกรToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim NextForm As Edit2 = New Edit2(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    ' Private Sub แสดงขอมลอปกรณToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles แสดงขอมลอปกรณToolStripMenuItem.Click
    '   Dim NextForm As Editdevice = New Editdevice(mysqlpass, ipconnect, usernamedb, dbname)
    '  Dim NextForm As main_user = New main_user()
    '    NextForm.Show()
    '  Me.Hide()
    ' End Sub

    Private Sub บนทกประวตบำรงรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บนทกประวตบำรงรกษาToolStripMenuItem.Click
        Dim NextForm As historydetail = New historydetail(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub จองอปกรณToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles จองอปกรณToolStripMenuItem.Click
        Dim NextForm As device_department = New device_department(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub จองอปกรณกลมToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles จองอปกรณกลมToolStripMenuItem.Click
        Dim NextForm As add_department_group = New add_department_group(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub แกไขแผนกToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles แกไขแผนกToolStripMenuItem.Click
        Dim NextForm As add_department_group = New add_department_group(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
        tabdepartname.Text = ""
    End Sub

    Private Sub บำรงรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บำรงรกษาToolStripMenuItem.Click
        Dim NextForm As addhistory = New addhistory(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub
End Class